package org.csu.code.api.controller;

import org.csu.code.api.common.CommonResponse;
import org.csu.code.api.entity.Farm;
import org.csu.code.api.service.FarmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class FarmController {
    @Autowired
    private FarmService farmService;

    @GetMapping("/farm/{id}")
    @ResponseBody
    public CommonResponse<Farm> getFarmByFarmId(@PathVariable("id") int farmId){
        return farmService.getFarmByFarmId(farmId);
    }

    @GetMapping("/account/users/{userId}/farm")
    @ResponseBody
    public CommonResponse<Farm> getFarmByUserId(@PathVariable("userId") int userId){
        return farmService.getFarmByUserId(userId);
    }

    @GetMapping("/farms")
    @ResponseBody
    public CommonResponse<List<Farm>> getAllFarms(){
        return farmService.getAllFarms();
    }


}
